﻿@{
    ViewBag.Title = "Index";
}


<div class="miniBar">

<div style="float: right;">

<div class="AddDialogBox" id="addNewTask">
    Add New Task
</div>

</div>
<div class="createNewBar">

<div id="allTasks" class="newDialogBox">
    <a href="#">All</a>
</div>

<div id="allOpenTasks" class="newDialogBox">
    <a href="#">Open</a>
</div>

<div id="completedTasks" class="newDialogBox">
    <a href="#">Completed</a>
</div>

@*<div class="newDialogBox">
    <a href="#">Today</a>
</div>

<div class="newDialogBox">
    <a href="#">Tomorrow</a>
</div>

<div class="newDialogBox">
    <a href="#">Later</a>
</div>

<div class="newDialogBox">
    <a href="#">No Date</a>
</div>*@

</div>

</div>

<div class="mainBlock">

<div class="leftDashboard">

<div class="taskBlock">
@Html.Partial("TaskListView")
</div>

</div>

<div class="rightDashboard">

<div class="categoryBlock">
@Html.Partial("CategoriesView")
</div>
</div>

</div>

<script type="text/javascript">

    $(document).ready(function () {

        /* Add New Task
        ***************************************************************************************************************************/
        $('#addNewTask').click(function () {
            $.ajax({
                url: '@(Url.Action("AddTask", "Task"))',
                type: "GET",
                dataType: "html",
                cache: false,
                success: function (data) {

                    $('#myDialogContainer').html(data);
                    $("#myDialogContainer").dialog({
                        autoOpen: false,
                        height: 500,
                        width: 600,
                        modal: true,
                        title: "Add New Task",
                        close: function () { }
                    });
                    $("#myDialogContainer").dialog("open");
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert('Error');
                }
            });
        });

        /* Edit a Task
        ***************************************************************************************************************************/
        $('.editBtn').live('click', function () {
            var taskId = $(this).attr("data-taskid");
            $.ajax({
                //url: '/Task/EditTask/?strTaskId=' + taskId,
                url: "@Url.Action("EditTask","Task")",
                type: "GET",
                dataType: "html",
                cache: false,
                data: {strTaskId: taskId},
                success: function (data) {

                    $('#myDialogContainer').html(data);
                    $("#myDialogContainer").dialog({
                        autoOpen: false,
                        height: 500,
                        width: 600,
                        modal: true,
                        title: "Edit Your Task",
                        close: function () { $(this).dialog("close"); }
                    });
                    $("#myDialogContainer").dialog("open"); //open it!
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert('Error');
                }

            });
        });

        /* Done a Task
        ***************************************************************************************************************************/
        $('.doneBtn').live('click', function () {
            var taskId = $(this).attr("data-taskid");

            if (confirm("Are you sure you have completed this ?")) {

                $.ajax({
                    //url: '/Task/TaskCompleted/?strTaskId=' + taskId,
                    url: "@Url.Action("TaskCompleted","Task")",
                    type: "POST",
                    data: {strTaskId:taskId},
                    context: this,
                    success: function (data) {
                        $(this).parent().parent().closest("div").remove();
                        loadCategories();
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert('Error');
                    }

                });
            }
        });

        /* Reopen a Task
        ***************************************************************************************************************************/
        $('.reopenBtn').live('click', function () {
            var taskId = $(this).attr("data-taskid");

            if (confirm("Are you sure, you want to Re-Open ?")) {
                $.ajax({
                    //url: '/Task/ReopenTask/?strTaskId=' + taskId,
                    url:"@Url.Action("ReopenTask","Task")",
                    type: "POST",
                    data: {strTaskId:taskId},
                    context: this,
                    success: function (data) {

                        $(this).parent().parent().closest("div").remove();
                        loadCategories();

                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert('Error');
                    }
                });
            }
        });

        /* Delete a Task
        ***************************************************************************************************************************/
        $('.deleteBtn').live('click', function () {
            var taskId = $(this).attr("data-taskid");

            if (confirm("Are you sure you want to delete this ?")) {
                $.ajax({
                        //url: '/Task/DeleteTask/?strTaskId=' + taskId,
                        url:"@Url.Action("DeleteTask","Task")",
                        type: "POST",
                        data: {strTaskId:taskId},
                        context: this,
                        success: function(data) {
                            $(this).parent().parent().closest("div").remove();
                            loadCategories();
                        },
                        error: function(xhr, ajaxOptions, thrownError) {
                            alert('Error');
                        }

                    });
            }
        });

        function loadCategories() {

            $("#mainCategory").text("");
            $("#mainCategory").append("<div class='loading'><img src='../../Content/Loading/loading2.gif' /></div>");

            var url = '@Url.Action("LoadCategories", "Task")';
            $.ajax({
                url: url,
                type: 'POST',
                cache: false,
                success: function (result) {
                    $("#mainCategory").hide();
                    $("#mainCategory").text("");
                    $("#mainCategory").append("<div id='newFeature' class='tags'>" + " <img src='@Url.Content("~/Content/Images/Category/new_feature.png")' /> <a href='#' >New Feature X " + result.NewFeatureCount + "</a></div>");
                    $("#mainCategory").append("<div id='change' class='tags'>" + " <img src='@Url.Content("~/Content/Images/Category/change.png")' /> <a href='#' >Change Request X " + result.ChangeRequestCount + "</a></div>");
                    $("#mainCategory").append("<div id='bug' class='tags'>" + " <img src='@Url.Content("~/Content/Images/Category/bug.png")' /> <a href='#' >Bugs X " + result.BugsCount + "</a></div>");
                    $("#mainCategory").append("<div id='todo' class='tags'>" + " <img src='@Url.Content("~/Content/Images/Category/todo.png")' /><a href='#' >Todo X " + result.TodoCount + "</a></div>");
                    $("#mainCategory").append("<div id='misc' class='tags'>" + " <img src='@Url.Content("~/Content/Images/Category/misc.png")' /><a href='#' >Miscellaneous X " + result.MiscCount + "</a></div>");
                    $("#mainCategory").fadeIn(400);

                },
                error: function () {
                    $("#mainCategory").text("");
                    $("#mainCategory").append("Error occured !");
                }
            });
        }
    });
        
</script>

<div id='myDialogContainer' style="display:none;">
</div>


